package com.ruoyi.production.service.impl.graftingclip;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.production.mapper.graftingclip.GraftingclipAmountMapper;
import com.ruoyi.production.domain.graftingclip.GraftingclipAmount;
import com.ruoyi.production.service.graftingclip.IGraftingclipAmountService;

/**
 * 嫁接夹量Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@Service
public class GraftingclipAmountServiceImpl implements IGraftingclipAmountService
{
    @Autowired
    private GraftingclipAmountMapper graftingclipAmountMapper;

    /**
     * 查询嫁接夹量
     *
     * @param graftingclipAmountId 嫁接夹量ID
     * @return 嫁接夹量
     */
    @Override
    public GraftingclipAmount selectGraftingclipAmountById(Long graftingclipAmountId)
    {
        return graftingclipAmountMapper.selectGraftingclipAmountById(graftingclipAmountId);
    }

    /**
     * 查询嫁接夹量列表
     *
     * @param graftingclipAmount 嫁接夹量
     * @return 嫁接夹量
     */
    @Override
    public List<GraftingclipAmount> selectGraftingclipAmountList(GraftingclipAmount graftingclipAmount)
    {
        return graftingclipAmountMapper.selectGraftingclipAmountList(graftingclipAmount);
    }

    /**
     * 新增嫁接夹量
     *
     * @param graftingclipAmount 嫁接夹量
     * @return 结果
     */
    @Override
    public int insertGraftingclipAmount(GraftingclipAmount graftingclipAmount)
    {
        graftingclipAmount.setCreateTime(DateUtils.getNowDate());
        //        向已有的数据直接在原来的基础上添加库存
        int r =graftingclipAmountMapper.updateGraftingclipAmount1(graftingclipAmount);
        if(r==0) {
            //        若原来的上面没有，则新加数据
            return graftingclipAmountMapper.insertGraftingclipAmount(graftingclipAmount);
        }
        return 1;

    }

    /**
     * 修改嫁接夹量
     *
     * @param graftingclipAmount 嫁接夹量
     * @return 结果
     */
    @Override
    public int updateGraftingclipAmount(GraftingclipAmount graftingclipAmount)
    {
        graftingclipAmount.setUpdateTime(DateUtils.getNowDate());
        //        删除这条数据，将这条数据当作新数据处理
        graftingclipAmountMapper.deleteGraftingclipAmountById(graftingclipAmount.getGraftingclipAmountId());
        //        若原来已有的数据，则向已有的数据直接在原来的基础上添加库存
        int r =graftingclipAmountMapper.updateGraftingclipAmount1(graftingclipAmount);
        if(r==0){
            //        若原来的上面没有，则当作新数据插入
            return graftingclipAmountMapper.insertGraftingclipAmount(graftingclipAmount);
        }
        return 1;
    }

    /**
     * 批量删除嫁接夹量
     *
     * @param graftingclipAmountIds 需要删除的嫁接夹量ID
     * @return 结果
     */
    @Override
    public int deleteGraftingclipAmountByIds(Long[] graftingclipAmountIds)
    {
        return graftingclipAmountMapper.deleteGraftingclipAmountByIds(graftingclipAmountIds);
    }

    /**
     * 删除嫁接夹量信息
     *
     * @param graftingclipAmountId 嫁接夹量ID
     * @return 结果
     */
    @Override
    public int deleteGraftingclipAmountById(Long graftingclipAmountId)
    {
        return graftingclipAmountMapper.deleteGraftingclipAmountById(graftingclipAmountId);
    }
}
